package cn.pfz.Utils;


import cn.hutool.core.date.DateUtil;
import com.alibaba.druid.support.json.JSONUtils;

import javax.xml.crypto.Data;
import java.lang.reflect.Field;
import java.util.Date;
import java.util.HashMap;

public class MyJsonUtil {


    public static   String getJson (Object o ,Class cl,String fomart)throws Exception{

        HashMap<String, Object> map = new HashMap();
        Field[] fields = cl.getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            if (field.getType().equals(Data.class)){
                String format = DateUtil.format((Date) field.get(o), fomart);
                map.put(field.getName(),format);
            }else {
                map.put(field.getName(),field.get(o));
            }
        }
        return JSONUtils.toJSONString(map);
    }
}
